#include "IpcMqttClientHandler.h"
#include "IpcMqttCommon.h"
#include "IpcMqttClientPublish.h"

#define DEF_TAG             "IpcMqttClientS"

void IpcMqttClientHandler_PropertyDevInfo(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *ProductID = OSC_cJSON_GetObjectItem(json_buf,"ProductID");
    ComNullRetVoid(ProductID);
    PRT_INFO(DEF_TAG,"ProductID: %s\n",ProductID->valuestring);

    OSC_cJSON *DeviceNum = OSC_cJSON_GetObjectItem(json_buf,"DeviceNum");
    ComNullRetVoid(DeviceNum);
    PRT_INFO(DEF_TAG,"DeviceNum: %s\n",DeviceNum->valuestring);

    OSC_cJSON *ProductType = OSC_cJSON_GetObjectItem(json_buf,"ProductType");
    ComNullRetVoid(ProductType);
    PRT_INFO(DEF_TAG,"ProductType: %s\n",ProductType->valuestring);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyDevInfo(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyNetInfo(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *DHCPMode = OSC_cJSON_GetObjectItem(json_buf,"DHCPMode");
    ComNullRetVoid(DHCPMode);
    PRT_INFO(DEF_TAG,"DHCPMode: %d\n",DHCPMode->valueint);

    OSC_cJSON *DevIP = OSC_cJSON_GetObjectItem(json_buf,"DevIP");
    ComNullRetVoid(DevIP);
    PRT_INFO(DEF_TAG,"DevIP: %s\n",DevIP->valuestring);

    OSC_cJSON *Netmask = OSC_cJSON_GetObjectItem(json_buf,"Netmask");
    ComNullRetVoid(Netmask);
    PRT_INFO(DEF_TAG,"Netmask: %s\n",Netmask->valuestring);

    OSC_cJSON *Gateway = OSC_cJSON_GetObjectItem(json_buf, "Gateway");
    ComNullRetVoid(Gateway);
    PRT_INFO(DEF_TAG, "Gateway: %s\n", Gateway->valuestring);

    OSC_cJSON *ServerIP = OSC_cJSON_GetObjectItem(json_buf, "ServerIP");
    ComNullRetVoid(ServerIP);
    PRT_INFO(DEF_TAG, "ServerIP: %s\n", ServerIP->valuestring);

    OSC_cJSON *Port = OSC_cJSON_GetObjectItem(json_buf, "Port");
    ComNullRetVoid(Port);
    PRT_INFO(DEF_TAG, "Port: %d\n", Port->valueint);

    OSC_cJSON *S_4G = OSC_cJSON_GetObjectItem(json_buf, "S_4G");
    ComNullRetVoid(S_4G);
    PRT_INFO(DEF_TAG, "S_4G: %d\n", S_4G->valueint);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyNetInfo(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyDevTime(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *Date = OSC_cJSON_GetObjectItem(json_buf,"Date");
    ComNullRetVoid(Date);
    PRT_INFO(DEF_TAG,"Date: %s\n",Date->valuestring);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyDevTime(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyVideoEncode(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *Resolution = OSC_cJSON_GetObjectItem(json_buf,"Resolution");
    ComNullRetVoid(Resolution);
    PRT_INFO(DEF_TAG,"Resolution: %s\n",Resolution->valuestring);

    OSC_cJSON *Fps = OSC_cJSON_GetObjectItem(json_buf,"Fps");
    ComNullRetVoid(Fps);
    PRT_INFO(DEF_TAG,"Fps: %d\n",Fps->valueint);

    OSC_cJSON *Gop = OSC_cJSON_GetObjectItem(json_buf, "Gop");
    ComNullRetVoid(Gop);
    PRT_INFO(DEF_TAG, "Gop: %d\n", Gop->valueint);

    OSC_cJSON *Encode = OSC_cJSON_GetObjectItem(json_buf, "Encode");
    ComNullRetVoid(Encode);
    PRT_INFO(DEF_TAG, "Encode: %d\n", Encode->valueint);

    OSC_cJSON *RcMode = OSC_cJSON_GetObjectItem(json_buf, "RcMode");
    ComNullRetVoid(RcMode);
    PRT_INFO(DEF_TAG, "RcMode: %d\n", RcMode->valueint);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyVideoEncode(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyIspParam(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *ColorMode = OSC_cJSON_GetObjectItem(json_buf, "ColorMode");
    ComNullRetVoid(ColorMode);
    PRT_INFO(DEF_TAG, "ColorMode: %d\n", ColorMode->valueint);

    OSC_cJSON *Luma = OSC_cJSON_GetObjectItem(json_buf, "Luma");
    ComNullRetVoid(Luma);
    PRT_INFO(DEF_TAG, "Luma: %d\n", Luma->valueint);

    OSC_cJSON *Contrast = OSC_cJSON_GetObjectItem(json_buf, "Contrast");
    ComNullRetVoid(Contrast);
    PRT_INFO(DEF_TAG, "Contrast: %d\n", Contrast->valueint);

    OSC_cJSON *Saturation = OSC_cJSON_GetObjectItem(json_buf, "Saturation");
    ComNullRetVoid(Saturation);
    PRT_INFO(DEF_TAG, "Saturation: %d\n", Saturation->valueint);

    OSC_cJSON *GainCtrl = OSC_cJSON_GetObjectItem(json_buf, "GainCtrl");
    ComNullRetVoid(GainCtrl);
    PRT_INFO(DEF_TAG, "GainCtrl: %d\n", GainCtrl->valueint);

    OSC_cJSON *Denoise = OSC_cJSON_GetObjectItem(json_buf, "Denoise");
    ComNullRetVoid(Denoise);
    PRT_INFO(DEF_TAG, "Denoise: %d\n", Denoise->valueint);

    OSC_cJSON *WB = OSC_cJSON_GetObjectItem(json_buf, "WB");
    ComNullRetVoid(WB);
    PRT_INFO(DEF_TAG, "WB: %d\n", WB->valueint);

    OSC_cJSON *DEFOG = OSC_cJSON_GetObjectItem(json_buf, "DEFOG");
    ComNullRetVoid(DEFOG);
    PRT_INFO(DEF_TAG, "DEFOG: %d\n", DEFOG->valueint);

    OSC_cJSON *BLC = OSC_cJSON_GetObjectItem(json_buf, "BLC");
    ComNullRetVoid(BLC);
    PRT_INFO(DEF_TAG, "BLC: %d\n", BLC->valueint);

    OSC_cJSON *Dynamic = OSC_cJSON_GetObjectItem(json_buf, "Dynamic");
    ComNullRetVoid(Dynamic);
    PRT_INFO(DEF_TAG, "Dynamic: %d\n", Dynamic->valueint);

    OSC_cJSON *HSBLC = OSC_cJSON_GetObjectItem(json_buf, "HSBLC");
    ComNullRetVoid(HSBLC);
    PRT_INFO(DEF_TAG, "HSBLC: %d\n", HSBLC->valueint);

    OSC_cJSON *VideoMode = OSC_cJSON_GetObjectItem(json_buf, "VideoMode");
    ComNullRetVoid(VideoMode);
    PRT_INFO(DEF_TAG, "VideoMode: %d\n", VideoMode->valueint);

    OSC_cJSON *NightModeTime = OSC_cJSON_GetObjectItem(json_buf, "NightModeTime");
    ComNullRetVoid(NightModeTime);
    PRT_INFO(DEF_TAG, "NightModeTime: %s\n", NightModeTime->valuestring);

    OSC_cJSON *Focus = OSC_cJSON_GetObjectItem(json_buf, "Focus");
    ComNullRetVoid(Focus);
    PRT_INFO(DEF_TAG, "Focus: %d\n", Focus->valueint);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyIspParam(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyRecordChn(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *RecordChn = OSC_cJSON_GetObjectItem(json_buf,"RecordChn");
    ComNullRetVoid(RecordChn);
    PRT_INFO(DEF_TAG,"RecordChn: %d\n",RecordChn->valueint);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyRecordChn(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyOSDMode(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *Position = OSC_cJSON_GetObjectItem(json_buf, "Position");
    ComNullRetVoid(Position);
    PRT_INFO(DEF_TAG, "Position: %d\n", Position->valueint);

    OSC_cJSON *TimeShow = OSC_cJSON_GetObjectItem(json_buf, "TimeShow");
    ComNullRetVoid(TimeShow);
    PRT_INFO(DEF_TAG, "TimeShow: %d\n", TimeShow->valueint);

    OSC_cJSON *VoltageShow = OSC_cJSON_GetObjectItem(json_buf, "VoltageShow");
    ComNullRetVoid(VoltageShow);
    PRT_INFO(DEF_TAG, "VoltageShow: %d\n", VoltageShow->valueint);

    OSC_cJSON *VoltageInfo = OSC_cJSON_GetObjectItem(json_buf, "VoltageInfo");
    ComNullRetVoid(VoltageInfo);
    PRT_INFO(DEF_TAG, "VoltageInfo: %s\n", VoltageInfo->valuestring);

    OSC_cJSON *BDShow = OSC_cJSON_GetObjectItem(json_buf, "BDShow");
    ComNullRetVoid(BDShow);
    PRT_INFO(DEF_TAG, "BDShow: %d\n", BDShow->valueint);

    OSC_cJSON *BDInfo = OSC_cJSON_GetObjectItem(json_buf, "BDInfo");
    ComNullRetVoid(BDInfo);
    PRT_INFO(DEF_TAG, "BDInfo: %s\n", BDInfo->valuestring);

    OSC_cJSON *MicroclimateShow = OSC_cJSON_GetObjectItem(json_buf, "MicroclimateShow");
    ComNullRetVoid(MicroclimateShow);
    PRT_INFO(DEF_TAG, "MicroclimateShow: %d\n", MicroclimateShow->valueint);

    OSC_cJSON *HumitureInfo = OSC_cJSON_GetObjectItem(json_buf, "HumitureInfo");
    ComNullRetVoid(HumitureInfo);
    PRT_INFO(DEF_TAG, "HumitureInfo: %s\n", HumitureInfo->valuestring);

    OSC_cJSON *WDIRInfo = OSC_cJSON_GetObjectItem(json_buf, "WDIRInfo");
    ComNullRetVoid(WDIRInfo);
    PRT_INFO(DEF_TAG, "WDIRInfo: %s\n", WDIRInfo->valuestring);

    OSC_cJSON *AirPressureInfo = OSC_cJSON_GetObjectItem(json_buf, "AirPressureInfo");
    ComNullRetVoid(AirPressureInfo);
    PRT_INFO(DEF_TAG, "AirPressureInfo: %s\n", AirPressureInfo->valuestring);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyOSDMode(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyCustomOSD(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *Position = OSC_cJSON_GetObjectItem(json_buf, "Position");
    ComNullRetVoid(Position);
    PRT_INFO(DEF_TAG, "Position: %d\n", Position->valueint);

    OSC_cJSON *ChnNameShow = OSC_cJSON_GetObjectItem(json_buf, "ChnNameShow");
    ComNullRetVoid(ChnNameShow);
    PRT_INFO(DEF_TAG, "ChnNameShow: %d\n", ChnNameShow->valueint);

    OSC_cJSON *ChnNameInfo = OSC_cJSON_GetObjectItem(json_buf, "ChnNameInfo");
    ComNullRetVoid(ChnNameInfo);
    PRT_INFO(DEF_TAG, "ChnNameInfo: %s\n", ChnNameInfo->valuestring);

    OSC_cJSON *CustomInfo = OSC_cJSON_GetObjectItem(json_buf, "CustomInfo");
    ComNullRetVoid(CustomInfo);

    int CustomInfo_num = OSC_cJSON_GetArraySize(CustomInfo);
    PRT_INFO(DEF_TAG, "CustomInfo_num: %d\n", CustomInfo_num);

    int i;
    for (i = 0; i < CustomInfo_num; i++)
    {
        OSC_cJSON *c_info = OSC_cJSON_GetArrayItem(CustomInfo, i);

        OSC_cJSON *StrShow = OSC_cJSON_GetObjectItem(c_info, "StrShow");
        ComNullRetVoid(StrShow);
        OSC_cJSON *StrInfo = OSC_cJSON_GetObjectItem(c_info, "StrInfo");
        ComNullRetVoid(StrInfo);
        PRT_INFO(DEF_TAG, "[%d]StrShow: %d,StrInfo: %s\n", i, StrShow->valueint, StrInfo->valuestring);
    }

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyCustomOSD(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyGB28181Param(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *Status = OSC_cJSON_GetObjectItem(json_buf, "Status");
    ComNullRetVoid(Status);
    PRT_INFO(DEF_TAG, "Status: %d\n", Status->valueint);

    OSC_cJSON *ServerIP = OSC_cJSON_GetObjectItem(json_buf, "ServerIP");
    ComNullRetVoid(ServerIP);
    PRT_INFO(DEF_TAG, "ServerIP: %s\n", ServerIP->valuestring);

    OSC_cJSON *Port = OSC_cJSON_GetObjectItem(json_buf, "Port");
    ComNullRetVoid(Port);
    PRT_INFO(DEF_TAG, "Port: %d\n", Port->valueint);

    OSC_cJSON *SIPID = OSC_cJSON_GetObjectItem(json_buf, "SIPID");
    ComNullRetVoid(SIPID);
    PRT_INFO(DEF_TAG, "SIPID: %s\n", SIPID->valuestring);

    OSC_cJSON *SIPDomain = OSC_cJSON_GetObjectItem(json_buf, "SIPDomain");
    ComNullRetVoid(SIPDomain);
    PRT_INFO(DEF_TAG, "SIPDomain: %s\n", SIPDomain->valuestring);

    OSC_cJSON *DevID = OSC_cJSON_GetObjectItem(json_buf, "DevID");
    ComNullRetVoid(DevID);
    PRT_INFO(DEF_TAG, "DevID: %s\n", DevID->valuestring);

    OSC_cJSON *DevName = OSC_cJSON_GetObjectItem(json_buf, "DevName");
    ComNullRetVoid(DevName);
    PRT_INFO(DEF_TAG, "DevName: %s\n", DevName->valuestring);

    OSC_cJSON *Password = OSC_cJSON_GetObjectItem(json_buf, "Password");
    ComNullRetVoid(Password);
    PRT_INFO(DEF_TAG, "Password: %s\n", Password->valuestring);

    OSC_cJSON *Protocol = OSC_cJSON_GetObjectItem(json_buf, "Protocol");
    ComNullRetVoid(Protocol);
    PRT_INFO(DEF_TAG, "Protocol: %d\n", Protocol->valueint);

    OSC_cJSON *RegExpires = OSC_cJSON_GetObjectItem(json_buf, "RegExpires");
    ComNullRetVoid(RegExpires);
    PRT_INFO(DEF_TAG, "RegExpires: %d\n", RegExpires->valueint);

    OSC_cJSON *Heartbeat = OSC_cJSON_GetObjectItem(json_buf, "Heartbeat");
    ComNullRetVoid(Heartbeat);
    PRT_INFO(DEF_TAG, "Heartbeat: %d\n", Heartbeat->valueint);

    OSC_cJSON *HeartbeatCnt = OSC_cJSON_GetObjectItem(json_buf, "HeartbeatCnt");
    ComNullRetVoid(HeartbeatCnt);
    PRT_INFO(DEF_TAG, "HeartbeatCnt: %d\n", HeartbeatCnt->valueint);

    OSC_cJSON *Cid = OSC_cJSON_GetObjectItem(json_buf, "Cid");
    ComNullRetVoid(Cid);
    PRT_INFO(DEF_TAG, "Cid: %s\n", Cid->valuestring);

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyGB28181Param(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyCruiseData(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *CruiseIndex = OSC_cJSON_GetObjectItem(json_buf, "CruiseIndex");
    ComNullRetVoid(CruiseIndex);
    PRT_INFO(DEF_TAG, "CruiseIndex: %d\n", CruiseIndex->valueint);

    OSC_cJSON *CruiseFlag = OSC_cJSON_GetObjectItem(json_buf, "CruiseFlag");
    ComNullRetVoid(CruiseFlag);
    PRT_INFO(DEF_TAG, "CruiseFlag: %d\n", CruiseFlag->valueint);

    OSC_cJSON *CruiseInfo = OSC_cJSON_GetObjectItem(json_buf, "CruiseInfo");
    ComNullRetVoid(CruiseInfo);

    int CruiseInfo_num = OSC_cJSON_GetArraySize(CruiseInfo);
    PRT_INFO(DEF_TAG, "CruiseInfo_num: %d\n", CruiseInfo_num);

    int i;
    for (i = 0; i < CruiseInfo_num; i++)
    {
        OSC_cJSON *c_info = OSC_cJSON_GetArrayItem(CruiseInfo, i);

        OSC_cJSON *CruisePointFlag = OSC_cJSON_GetObjectItem(c_info, "CruisePointFlag");
        ComNullRetVoid(CruisePointFlag);
        OSC_cJSON *CruisePreset = OSC_cJSON_GetObjectItem(c_info, "CruisePreset");
        ComNullRetVoid(CruisePreset);
        OSC_cJSON *CruiseSpeed = OSC_cJSON_GetObjectItem(c_info, "CruiseSpeed");
        ComNullRetVoid(CruiseSpeed);
        OSC_cJSON *CruiseTime = OSC_cJSON_GetObjectItem(c_info, "CruiseTime");
        ComNullRetVoid(CruiseTime);

        PRT_INFO(DEF_TAG, "[%d]F%d-P%03d-S%d-T%03d\n", i, CruisePreset->valueint, CruisePointFlag->valueint, CruiseSpeed->valueint,CruiseTime->valueint);
    }

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyCruiseData(p_info->Data,CruiseIndex->valueint);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

void IpcMqttClientHandler_PropertyTimingSnapshot(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *TimingInfo = OSC_cJSON_GetObjectItem(json_buf, "TimingInfo");
    ComNullRetVoid(TimingInfo);

    int TimingInfo_num = OSC_cJSON_GetArraySize(TimingInfo);
    PRT_INFO(DEF_TAG, "TimingInfo_num: %d\n", TimingInfo_num);

    int i;
    for (i = 0; i < TimingInfo_num; i++)
    {
        OSC_cJSON *t_info = OSC_cJSON_GetArrayItem(TimingInfo, i);

        OSC_cJSON *Hour = OSC_cJSON_GetObjectItem(t_info, "Hour");
        ComNullRetVoid(Hour);
        OSC_cJSON *Minute = OSC_cJSON_GetObjectItem(t_info, "Minute");
        ComNullRetVoid(Minute);
        OSC_cJSON *PresetNum = OSC_cJSON_GetObjectItem(t_info, "PresetNum");
        ComNullRetVoid(PresetNum);
        PRT_INFO(DEF_TAG, "[%d]P%03d-Time:%02d:%02d\n", i, PresetNum->valueint, Hour->valueint, Minute->valueint);
    }

    p_info->Data = OSC_cJSON_CreateObject();
    Ext_IpcMqttClientPublish_PropertyTimingSnapshot(p_info->Data);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_PROPERTY_POST);
}

Com_s32 IpcMqttClientHandler_DataParse(OSC_cJSON *json_buf, pStIpcMqttComPublishInfo p_info)
{
    OSC_cJSON *Cmd = OSC_cJSON_GetObjectItem(json_buf, "Cmd");
    ComNullRetInt(Cmd);
    p_info->Cmd = Cmd->valuestring;

    OSC_cJSON *DevChn = OSC_cJSON_GetObjectItem(json_buf, "DevChn");
    ComNullRetInt(DevChn);
    p_info->DevChn = DevChn->valueint;

    OSC_cJSON *MsgID = OSC_cJSON_GetObjectItem(json_buf, "MsgID");
    ComNullRetInt(MsgID);
    p_info->MsgID = MsgID->valuestring;

    return DEF_COM_SUCCESS;
}

StIpcMqttPropertyHandlerInfo g_IpcMqttProperty_InfoTable[] = {
    {IPC_MQTT_PROPERTY_POSTVERINFO , NULL},
    {IPC_MQTT_PROPERTY_DEVINFO , IpcMqttClientHandler_PropertyDevInfo},
    {IPC_MQTT_PROPERTY_NETINFO , IpcMqttClientHandler_PropertyNetInfo},
    {IPC_MQTT_PROPERTY_DEVTIME , IpcMqttClientHandler_PropertyDevTime},
    {IPC_MQTT_PROPERTY_VIDEOENCODE , IpcMqttClientHandler_PropertyVideoEncode},
    {IPC_MQTT_PROPERTY_ISPPARAM , IpcMqttClientHandler_PropertyIspParam},
    {IPC_MQTT_PROPERTY_RECORDCHN , IpcMqttClientHandler_PropertyRecordChn},
    {IPC_MQTT_PROPERTY_OSDMODE , IpcMqttClientHandler_PropertyOSDMode},
    {IPC_MQTT_PROPERTY_CUSTOMOSD , IpcMqttClientHandler_PropertyCustomOSD},
    {IPC_MQTT_PROPERTY_GB28181PARAM , IpcMqttClientHandler_PropertyGB28181Param},
    {IPC_MQTT_PROPERTY_CRUISEDATA , IpcMqttClientHandler_PropertyCruiseData},
    {IPC_MQTT_PROPERTY_POSTTFINFO , NULL},
    {IPC_MQTT_PROPERTY_TIMINGSNAPSHOT , IpcMqttClientHandler_PropertyTimingSnapshot},
};

void IpcMqttClientHandler_Property(void *client, message_data_t *msg)
{
    PRT_NORMAL("\ntopic: %s\n", msg->topic_name);
    PRT_NORMAL("len: %d \n%s\n", (int)msg->message->payloadlen, (char *)msg->message->payload);

    Com_s32 ret;
    OSC_cJSON *json_buf = OSC_cJSON_Parse((char *)msg->message->payload);
    ComNullRetVoid(json_buf);

    StIpcMqttComPublishInfo p_info;
    memset(&p_info,0,sizeof(p_info));

    ret = IpcMqttClientHandler_DataParse(json_buf,&p_info);
    if(ret == DEF_COM_FAILED)
    {
        goto exit;
    }

    p_info.qos = msg->message->qos;
    p_info.client = (mqtt_client_t *)client;

    pStIpcMqttComCmdInfo cmd_data = Ext_Get_g_IpcMqttProperty_CmdData();
    int i;
    for (i = 0; i < IPC_MQTT_PROPERTY_MAX; i++)
    {
        if (strcmp(p_info.Cmd, cmd_data[i].mqtt_cmd) == 0)
        {
            if (i == g_IpcMqttProperty_InfoTable[i].id)
            {
                if (g_IpcMqttProperty_InfoTable[i].handler != NULL)
                {
                    OSC_cJSON *Data = OSC_cJSON_GetObjectItem(json_buf, "Data");
                    ComNullRetVoid(Data);
                    g_IpcMqttProperty_InfoTable[i].handler(Data, &p_info);
                }
            }
        }
    }

exit:
    OSC_cJSON_Delete(json_buf);
}

void IpcMqttClientHandler_ServicePtzCtrl(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 命令（内容如EnIpcMqttPtzCmd）
    OSC_cJSON *PtzCmd = OSC_cJSON_GetObjectItem(json_buf,"PtzCmd");
    ComNullRetVoid(PtzCmd);
    PRT_INFO(DEF_TAG,"PtzCmd: %d\n",PtzCmd->valueint);

    // 状态，0：开始，1：停止
    OSC_cJSON *PtzStatus = OSC_cJSON_GetObjectItem(json_buf, "PtzStatus");
    ComNullRetVoid(PtzStatus);
    PRT_INFO(DEF_TAG, "PtzStatus: %d\n", PtzStatus->valueint);

    // 速度，取值范围[1，8]
    OSC_cJSON *PtzSpeed = OSC_cJSON_GetObjectItem(json_buf, "PtzSpeed");
    ComNullRetVoid(PtzSpeed);
    PRT_INFO(DEF_TAG, "PtzSpeed: %d\n", PtzSpeed->valueint);

    p_info->Data = OSC_cJSON_Duplicate(json_buf,1);
    /***
    如果要修改内容则使用以下注释代码
    OSC_cJSON *P_PtzCmd = OSC_cJSON_GetObjectItem(p_info->Data,"PtzCmd");
    ComNullRetVoid(P_PtzCmd);
    P_PtzCmd->valueint = 10;
    ***/
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_ServicePtzPreset(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 命令，0：清除；1：设置；2：调用
    OSC_cJSON *PtzPresetCmd = OSC_cJSON_GetObjectItem(json_buf,"PtzPresetCmd");
    ComNullRetVoid(PtzPresetCmd);
    PRT_INFO(DEF_TAG,"PtzPresetCmd: %d\n",PtzPresetCmd->valueint);

    // 预置点，取值范围[1，128]
    OSC_cJSON *PtzPresetPoints = OSC_cJSON_GetObjectItem(json_buf, "PtzPresetPoints");
    ComNullRetVoid(PtzPresetPoints);
    PRT_INFO(DEF_TAG, "PtzPresetPoints: %d\n", PtzPresetPoints->valueint);

    p_info->Data = OSC_cJSON_Duplicate(json_buf,1);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_ServicePtzCruise(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 命令，0：将预置点从巡航序列中删除，1：将预置点加入巡航序列，2：删指定的巡航路线，3：开始巡航，4：停止巡航
    OSC_cJSON *PtzCruiseCmd = OSC_cJSON_GetObjectItem(json_buf, "PtzCruiseCmd");
    ComNullRetVoid(PtzCruiseCmd);
    PRT_INFO(DEF_TAG, "PtzCruiseCmd: %d\n", PtzCruiseCmd->valueint);

    // 巡航路线，取值范围[1-8]
    OSC_cJSON *PtzCruiseRoute = OSC_cJSON_GetObjectItem(json_buf, "PtzCruiseRoute");
    ComNullRetVoid(PtzCruiseRoute);
    PRT_INFO(DEF_TAG, "PtzCruiseRoute: %d\n", PtzCruiseRoute->valueint);

    // 巡航点，取值范围[1-32]
    OSC_cJSON *PtzCruisePoint = OSC_cJSON_GetObjectItem(json_buf, "PtzCruisePoint");
    ComNullRetVoid(PtzCruisePoint);
    PRT_INFO(DEF_TAG, "PtzCruisePoint: %d\n", PtzCruisePoint->valueint);

    // 预置点，取值范围[1,300]
    OSC_cJSON *PtzPresetPoints = OSC_cJSON_GetObjectItem(json_buf, "PtzPresetPoints");
    ComNullRetVoid(PtzPresetPoints);
    PRT_INFO(DEF_TAG, "PtzPresetPoints: %d\n", PtzPresetPoints->valueint);

    // 速度，取值范围[1,8]
    OSC_cJSON *PtzSpeed = OSC_cJSON_GetObjectItem(json_buf, "PtzSpeed");
    ComNullRetVoid(PtzSpeed);
    PRT_INFO(DEF_TAG, "PtzSpeed: %d\n", PtzSpeed->valueint);

    // 时间，取值范围[1,255]，单位为秒
    OSC_cJSON *PtzTime = OSC_cJSON_GetObjectItem(json_buf, "PtzTime");
    ComNullRetVoid(PtzTime);
    PRT_INFO(DEF_TAG, "PtzTime: %d\n", PtzTime->valueint);

    p_info->Data = OSC_cJSON_Duplicate(json_buf, 1);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info, IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_Service3DPos(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 命令，1：放大，2：缩小
    OSC_cJSON *S_3DPosCmd = OSC_cJSON_GetObjectItem(json_buf,"S_3DPosCmd");
    ComNullRetVoid(S_3DPosCmd);
    PRT_INFO(DEF_TAG,"S_3DPosCmd: %d\n",S_3DPosCmd->valueint);

    // 选择窗口开始点的 X 坐标（1-255）
    OSC_cJSON *S_3DPosStartX = OSC_cJSON_GetObjectItem(json_buf, "S_3DPosStartX");
    ComNullRetVoid(S_3DPosStartX);
    PRT_INFO(DEF_TAG, "S_3DPosStartX: %d\n", S_3DPosStartX->valueint);

    // 选择窗口开始点的 Y 坐标（1-255）
    OSC_cJSON *S_3DPosStartY = OSC_cJSON_GetObjectItem(json_buf, "S_3DPosStartY");
    ComNullRetVoid(S_3DPosStartY);
    PRT_INFO(DEF_TAG, "S_3DPosStartY: %d\n", S_3DPosStartY->valueint);

    // 选择窗口结束点的 X 坐标（1-255） 结束点坐标大于开始点，放大
    OSC_cJSON *S_3DPosEndX = OSC_cJSON_GetObjectItem(json_buf, "S_3DPosEndX");
    ComNullRetVoid(S_3DPosEndX);
    PRT_INFO(DEF_TAG, "S_3DPosEndX: %d\n", S_3DPosEndX->valueint);

    // 选择窗口结束点的 Y 坐标（1-255） 结束点坐标小于开始点，缩小
    OSC_cJSON *S_3DPosEndY = OSC_cJSON_GetObjectItem(json_buf, "S_3DPosEndY");
    ComNullRetVoid(S_3DPosEndY);
    PRT_INFO(DEF_TAG, "S_3DPosEndY: %d\n", S_3DPosEndY->valueint);

    p_info->Data = OSC_cJSON_CreateObject();
    // 0：成功；1：数据有误，2：不支持该命令
    OSC_cJSON_AddNumberToObject(p_info->Data, "S_3DPosRet", 2);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_ServiceManualSnapshot(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 图片上传路径，默认值"http://192.168.1.1/pic"
    OSC_cJSON *Url = OSC_cJSON_GetObjectItem(json_buf,"Url");
    ComNullRetVoid(Url);
    PRT_INFO(DEF_TAG,"Url: %s\n",Url->valuestring);

    p_info->Data = OSC_cJSON_Duplicate(json_buf,1);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_ServiceReboot(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    p_info->Data = OSC_cJSON_CreateObject();
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info,IPC_MQTT_COM_TOPIC_SERVICE_POST);

    //Ext_InSdkTcp_SystemCmd("reboot");
}

void IpcMqttClientHandler_ServiceMediaLive(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 命令，1：开始播放，2：结束播放
    OSC_cJSON *LiveCmd = OSC_cJSON_GetObjectItem(json_buf, "LiveCmd");
    ComNullRetVoid(LiveCmd);
    PRT_INFO(DEF_TAG, "LiveCmd: %d\n", LiveCmd->valueint);

    // 数据，1：视频，2：音频，3：视频+音频
    OSC_cJSON *LiveType = OSC_cJSON_GetObjectItem(json_buf, "LiveType");
    ComNullRetVoid(LiveType);
    PRT_INFO(DEF_TAG, "LiveType: %d\n", LiveType->valueint);

    // 码流，1：主码流，2：子码流
    OSC_cJSON *LiveChn = OSC_cJSON_GetObjectItem(json_buf, "LiveChn");
    ComNullRetVoid(LiveChn);
    PRT_INFO(DEF_TAG, "LiveChn: %d\n", LiveChn->valueint);

    // 传输协议，1：TCP，2：UDP
    OSC_cJSON *LiveProtocol = OSC_cJSON_GetObjectItem(json_buf, "LiveProtocol");
    ComNullRetVoid(LiveProtocol);
    PRT_INFO(DEF_TAG, "LiveProtocol: %d\n", LiveProtocol->valueint);

    // 主机IP
    OSC_cJSON *HostIP = OSC_cJSON_GetObjectItem(json_buf, "HostIP");
    ComNullRetVoid(HostIP);
    PRT_INFO(DEF_TAG, "HostIP: %s\n", HostIP->valuestring);

    // 主机端口
    OSC_cJSON *HostPort = OSC_cJSON_GetObjectItem(json_buf, "HostPort");
    ComNullRetVoid(HostPort);
    PRT_INFO(DEF_TAG, "HostPort: %d\n", HostPort->valueint);

    p_info->Data = OSC_cJSON_CreateObject();
    // 命令状态，0：正常，1：出错
    OSC_cJSON_AddNumberToObject(p_info->Data, "LiveStatus", 0);
    // 出错类型，0：无错误，1：无数据，2：无码流，3：不支持的协议，4：其它错误
    OSC_cJSON_AddNumberToObject(p_info->Data, "LiveError", 0);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info, IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_ServiceTFUse(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // TF卡命令类型：1：挂载命令，2：卸载命令，3：格式化
    OSC_cJSON *TFCmd = OSC_cJSON_GetObjectItem(json_buf, "TFCmd");
    ComNullRetVoid(TFCmd);
    PRT_INFO(DEF_TAG, "TFCmd: %d\n", TFCmd->valueint);

    p_info->Data = OSC_cJSON_Duplicate(json_buf,1);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info, IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

void IpcMqttClientHandler_ServiceOTA(OSC_cJSON *json_buf,pStIpcMqttComPublishInfo p_info)
{
    // 升级类型：0：底座摄像头，1：云台摄像头，2：云台机器
    OSC_cJSON *OtaType = OSC_cJSON_GetObjectItem(json_buf, "OtaType");
    ComNullRetVoid(OtaType);
    PRT_INFO(DEF_TAG, "OtaType: %d\n", OtaType->valueint);

    // 升级包名称
    OSC_cJSON *OtaName = OSC_cJSON_GetObjectItem(json_buf, "OtaName");
    ComNullRetVoid(OtaName);
    PRT_INFO(DEF_TAG, "OtaName: %s\n", OtaName->valuestring);

    // 升级包下载链接（完整链接要带升级包名称）
    OSC_cJSON *OtaUrl = OSC_cJSON_GetObjectItem(json_buf, "OtaUrl");
    ComNullRetVoid(OtaUrl);
    PRT_INFO(DEF_TAG, "OtaUrl: %s\n", OtaUrl->valuestring);

    p_info->Data = OSC_cJSON_Duplicate(json_buf,1);
    OSC_cJSON_AddNumberToObject(p_info->Data, "ErrorCode", 0);
    Ext_IpcMqttClientPublish_Msg(p_info, IPC_MQTT_COM_TOPIC_SERVICE_POST);
}

StIpcMqttPropertyHandlerInfo g_IpcMqttService_InfoTable[] = {
    {IPC_MQTT_SERVICE_PTZCTRL , IpcMqttClientHandler_ServicePtzCtrl},
    {IPC_MQTT_SERVICE_PTZPRESET , IpcMqttClientHandler_ServicePtzPreset},
    {IPC_MQTT_SERVICE_PTZCRUISE , IpcMqttClientHandler_ServicePtzCruise},
    {IPC_MQTT_SERVICE_3DPOS , IpcMqttClientHandler_Service3DPos},
    {IPC_MQTT_SERVICE_MANUALSNAPSHOT , IpcMqttClientHandler_ServiceManualSnapshot},
    {IPC_MQTT_SERVICE_REBOOT , IpcMqttClientHandler_ServiceReboot},
    {IPC_MQTT_SERVICE_MEDIALIVE , IpcMqttClientHandler_ServiceMediaLive},
    {IPC_MQTT_SERVICE_TFUSE , IpcMqttClientHandler_ServiceTFUse},
    {IPC_MQTT_SERVICE_OTA , IpcMqttClientHandler_ServiceOTA},
};

void IpcMqttClientHandler_Service(void *client, message_data_t *msg)
{
    PRT_NORMAL("\ntopic: %s\n",msg->topic_name);
    PRT_NORMAL("len: %d \n%s\n",(int)msg->message->payloadlen,(char *)msg->message->payload);
    Com_s32 ret;
    OSC_cJSON *json_buf = OSC_cJSON_Parse((char *)msg->message->payload);
    ComNullRetVoid(json_buf);

    StIpcMqttComPublishInfo p_info;
    memset(&p_info,0,sizeof(p_info));

    ret = IpcMqttClientHandler_DataParse(json_buf,&p_info);
    if(ret == DEF_COM_FAILED)
    {
        goto exit;
    }

    p_info.qos = msg->message->qos;
    p_info.client = (mqtt_client_t *)client;

    pStIpcMqttComCmdInfo cmd_data = Ext_Get_g_IpcMqttService_CmdData();
    int i;
    for (i = 0; i < IPC_MQTT_PROPERTY_MAX; i++)
    {
        if (strcmp(p_info.Cmd, cmd_data[i].mqtt_cmd) == 0)
        {
            if (i == g_IpcMqttService_InfoTable[i].id)
            {
                if (g_IpcMqttService_InfoTable[i].handler != NULL)
                {
                    OSC_cJSON *Data = OSC_cJSON_GetObjectItem(json_buf, "Data");
                    ComNullRetVoid(Data);
                    g_IpcMqttService_InfoTable[i].handler(Data, &p_info);
                }
            }
        }
    }

exit:
    OSC_cJSON_Delete(json_buf);
}

void Ext_IpcMqttClientHandler_SubscribeInit(mqtt_client_t *client)
{
    mqtt_subscribe(client, Ext_Get_g_IpcMqttTopic_Info(IPC_MQTT_COM_TOPIC_PROPERTY_GET), QOS0, IpcMqttClientHandler_Property);
    mqtt_subscribe(client, Ext_Get_g_IpcMqttTopic_Info(IPC_MQTT_COM_TOPIC_SERVICE_GET), QOS0, IpcMqttClientHandler_Service);
}
